import request from '@/utils/request'
import type {
  tradmarkInfoResponseData,
  spuImageResponseData,
  spuSaleAttrResponseData,
  HasSaleAttrResponseData,
  spuInfoData
} from './type'
enum API {
  SPUATTRLIST_URL = '/admin/product/',
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取某个SPU下的全部的售卖商品的图片数据
  IMAGE_URL = '/admin/product/spuImageList/',
  //获取某一个SPU下全部的已有的销售属性接口地址
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  //获取整个项目全部的销售属性[颜色、版本、尺码]
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  //追加一个新的SPU
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  //更新已有的SPU
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  //追加一个新增的SKU地址
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  //查看某一个已有的SPU下全部售卖的商品
  SKUINFO_URL = '/admin/product/findBySpuId/',
  //删除已有的SPU
  REMOVESPU_URL = '/admin/product/deleteSpu/',
  ADDSPUINFO_URL = '/admin/product/saveSpuInfo',
  UPDATESPUINFO_URL = '/admin/product/updateSpuInfo'
}
export const reqSpuInfoList = (page: number, limit: number, c3Id: any) => {
  return request.get<any, any>(API.SPUATTRLIST_URL + `${page}/${limit}?category3Id=${c3Id}`)
}
export const reqAllTradmarkList = () => {
  return request.get<any, tradmarkInfoResponseData>(API.ALLTRADEMARK_URL)
}
export const reqSpuImageList = (spuId: number) =>
  request.get<any, spuImageResponseData>(API.IMAGE_URL + spuId)
export const reqSpuSaleAttr = (spuId: number) => {
  return request.get<any, spuSaleAttrResponseData>(API.SPUHASSALEATTR_URL + `${spuId}`)
}
export const reqAllSpuSaleAttr = () => {
  return request.get<any, HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
}
export const reqAddOrUpdateSpuInfo = (data: any) => {
  if (data.id) {
    return request.post(API.UPDATESPUINFO_URL, data)
  } else {
    return request.post(API.ADDSPUINFO_URL, data)
  }
}
export const reqAddSku = (data: any) => {
  return request.post<any, any>(API.ADDSKU_URL, data)
}
export const reqSkuList = (spuId: string) => {
  return request.get<any, any>(API.SKUINFO_URL + `${spuId}`)
}
